package top.ffhome.system.service.audit;

import java.util.Date;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import top.ffhome.common.audit.AbstractAuditLogAspect;
import top.ffhome.common.utils.IpUtils;
import top.ffhome.system.config.shiro.CurrentUser;
import top.ffhome.system.entity.SysAuditLog;
import top.ffhome.system.mapper.SysAuditLogMapper;

/**
 * 数据更改日志AOP处理器,保存至AuditLog对应表中
 * 
 * @author John
 */
@Aspect
@Component
public class AuditLogAspect extends AbstractAuditLogAspect {
	@Autowired
	private SysAuditLogMapper auditLogMapper;
	@Autowired
	private CurrentUser currentUser;

	@Override
	protected void writeAuditLog(String functionName, int type, String entityName, Long dataId, String content) {
		SysAuditLog auditLog = new SysAuditLog();
		auditLog.setFunctionName(functionName);
		auditLog.setContent(content);
		auditLog.setCreateBy(currentUser.getId());
		auditLog.setCreateTime(new Date());
		auditLog.setDataId(dataId);
		auditLog.setEntityName(entityName);
		auditLog.setIp(IpUtils.getIp());
		auditLog.setType("" + type);
		auditLogMapper.insert(auditLog);
	}
}
